from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-06 14:06:01.552213
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 06, Feb, 2021
Time: 14:06:06
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.9141
Nobs: 194.000 HQIC: -46.8162
Log likelihood: 2213.25 FPE: 2.52188e-21
AIC: -47.4301 Det(Omega_mle): 1.60423e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.457963 0.141382 3.239 0.001
L1.Burgenland 0.099238 0.073271 1.354 0.176
L1.Kärnten -0.219796 0.060760 -3.617 0.000
L1.Niederösterreich 0.122256 0.169987 0.719 0.472
L1.Oberösterreich 0.224175 0.148652 1.508 0.132
L1.Salzburg 0.200624 0.078692 2.549 0.011
L1.Steiermark 0.103998 0.106018 0.981 0.327
L1.Tirol 0.153576 0.071117 2.159 0.031
L1.Vorarlberg -0.004723 0.064967 -0.073 0.942
L1.Wien -0.123682 0.142635 -0.867 0.386
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.499051 0.174662 2.857 0.004
L1.Burgenland 0.016903 0.090519 0.187 0.852
L1.Kärnten 0.365778 0.075063 4.873 0.000
L1.Niederösterreich 0.116126 0.210001 0.553 0.580
L1.Oberösterreich -0.146386 0.183644 -0.797 0.425
L1.Salzburg 0.194703 0.097216 2.003 0.045
L1.Steiermark 0.234009 0.130974 1.787 0.074
L1.Tirol 0.140783 0.087857 1.602 0.109
L1.Vorarlberg 0.177249 0.080260 2.208 0.027
L1.Wien -0.586417 0.176210 -3.328 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.303353 0.062945 4.819 0.000
L1.Burgenland 0.106466 0.032621 3.264 0.001
L1.Kärnten -0.020622 0.027051 -0.762 0.446
L1.Niederösterreich 0.068055 0.075681 0.899 0.369
L1.Oberösterreich 0.283994 0.066182 4.291 0.000
L1.Salzburg 0.005065 0.035035 0.145 0.885
L1.Steiermark -0.017243 0.047201 -0.365 0.715
L1.Tirol 0.090767 0.031662 2.867 0.004
L1.Vorarlberg 0.110078 0.028924 3.806 0.000
L1.Wien 0.075313 0.063503 1.186 0.236
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.222528 0.071621 3.107 0.002
L1.Burgenland -0.014333 0.037118 -0.386 0.699
L1.Kärnten 0.024069 0.030780 0.782 0.434
L1.Niederösterreich 0.035025 0.086112 0.407 0.684
L1.Oberösterreich 0.385490 0.075304 5.119 0.000
L1.Salzburg 0.094398 0.039864 2.368 0.018
L1.Steiermark 0.184945 0.053707 3.444 0.001
L1.Tirol 0.040175 0.036026 1.115 0.265
L1.Vorarlberg 0.090722 0.032911 2.757 0.006
L1.Wien -0.065349 0.072256 -0.904 0.366
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.527387 0.143304 3.680 0.000
L1.Burgenland 0.062174 0.074267 0.837 0.402
L1.Kärnten 0.014689 0.061586 0.239 0.811
L1.Niederösterreich -0.022518 0.172298 -0.131 0.896
L1.Oberösterreich 0.156038 0.150673 1.036 0.300
L1.Salzburg 0.052959 0.079762 0.664 0.507
L1.Steiermark 0.121563 0.107460 1.131 0.258
L1.Tirol 0.206879 0.072084 2.870 0.004
L1.Vorarlberg 0.028036 0.065850 0.426 0.670
L1.Wien -0.136211 0.144574 -0.942 0.346
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162455 0.101135 1.606 0.108
L1.Burgenland -0.023670 0.052413 -0.452 0.652
L1.Kärnten -0.012439 0.043464 -0.286 0.775
L1.Niederösterreich 0.121706 0.121597 1.001 0.317
L1.Oberösterreich 0.397478 0.106336 3.738 0.000
L1.Salzburg -0.020823 0.056291 -0.370 0.711
L1.Steiermark -0.028951 0.075838 -0.382 0.703
L1.Tirol 0.189881 0.050872 3.733 0.000
L1.Vorarlberg 0.036050 0.046473 0.776 0.438
L1.Wien 0.185820 0.102031 1.821 0.069
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.232777 0.129594 1.796 0.072
L1.Burgenland 0.063687 0.067162 0.948 0.343
L1.Kärnten -0.040234 0.055694 -0.722 0.470
L1.Niederösterreich -0.031964 0.155814 -0.205 0.837
L1.Oberösterreich -0.095692 0.136258 -0.702 0.483
L1.Salzburg 0.033474 0.072131 0.464 0.643
L1.Steiermark 0.395970 0.097179 4.075 0.000
L1.Tirol 0.492336 0.065187 7.553 0.000
L1.Vorarlberg 0.164141 0.059550 2.756 0.006
L1.Wien -0.212918 0.130743 -1.629 0.103
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.079115 0.156255 0.506 0.613
L1.Burgenland 0.031516 0.080979 0.389 0.697
L1.Kärnten -0.090019 0.067152 -1.341 0.180
L1.Niederösterreich 0.246815 0.187869 1.314 0.189
L1.Oberösterreich 0.002063 0.164290 0.013 0.990
L1.Salzburg 0.230122 0.086971 2.646 0.008
L1.Steiermark 0.126388 0.117171 1.079 0.281
L1.Tirol 0.072251 0.078598 0.919 0.358
L1.Vorarlberg 0.041863 0.071801 0.583 0.560
L1.Wien 0.266830 0.157640 1.693 0.091
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.593945 0.082520 7.198 0.000
L1.Burgenland -0.026322 0.042766 -0.615 0.538
L1.Kärnten -0.002938 0.035464 -0.083 0.934
L1.Niederösterreich -0.041728 0.099216 -0.421 0.674
L1.Oberösterreich 0.286780 0.086763 3.305 0.001
L1.Salzburg 0.018226 0.045930 0.397 0.692
L1.Steiermark 0.017000 0.061879 0.275 0.784
L1.Tirol 0.079163 0.041508 1.907 0.056
L1.Vorarlberg 0.137914 0.037919 3.637 0.000
L1.Wien -0.057267 0.083251 -0.688 0.492
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.140370 0.032185 0.210275 0.259887 0.075050 0.091374 -0.056056 0.171404
Kärnten 0.140370 1.000000 0.015901 0.192422 0.162219 -0.112959 0.165218 0.023886 0.311791
Niederösterreich 0.032185 0.015901 1.000000 0.311008 0.089948 0.221395 0.142896 0.054679 0.369530
Oberösterreich 0.210275 0.192422 0.311008 1.000000 0.304058 0.297185 0.112866 0.080836 0.136625
Salzburg 0.259887 0.162219 0.089948 0.304058 1.000000 0.156751 0.064106 0.087458 -0.016353
Steiermark 0.075050 -0.112959 0.221395 0.297185 0.156751 1.000000 0.117858 0.091239 -0.086614
Tirol 0.091374 0.165218 0.142896 0.112866 0.064106 0.117858 1.000000 0.163096 0.154794
Vorarlberg -0.056056 0.023886 0.054679 0.080836 0.087458 0.091239 0.163096 1.000000 0.073998
Wien 0.171404 0.311791 0.369530 0.136625 -0.016353 -0.086614 0.154794 0.073998 1.000000